"use strict";
require('console.table');
var chai = require('chai');
var co = require('co');
var expect = chai.expect;
var SurveyFitLine = require('../service/SurveyFitLine.js');
var models = require('../models/index.js');
var moment = require('moment');

describe('人工实测线路功能测试', function () {
    it.only('#从数据库读取数据并按照要求进行拟合', function () {
        return co(function* () {
            var surveyCenters = yield models.SurveyCenter.findAll({
                where: {
                    $and: {
                        prjId: 3,
                        no: {
                            $ne: null
                        },
                        e: {
                            $ne: null
                        }
                    }
                },
                order: [["Id", "ASC"], ['No', 'ASC']]
            });
            var data = surveyCenters.map(function (item) {
                return item.dataValues;
            });
            console.table(data);
            expect(surveyCenters.length).to.be.equal(88);
        });
    });

    it('#能够通过给定坐标,返回所在的里程', function () {
        return co(function* (next) {
            var line = yield SurveyFitLine.getLineFromDb(1);
            var coor = line.getCoorAtMile(108);
            expect(coor).to.have.property('e');
            console.log('\t', coor);
        });
    });

    it('#能够查询里程推进的累计值', function () {
        return co(function* () {
            // yield models.DistMileResult.create({
            //     configId: 1,
            //     deviceId: 128,
            //     value: 1.23,
            //     date: new Date()
            // });
            var mileSums = yield models.sequelize.query('select sum(Value) as mileSum from DistMileResult where DeviceId = ' + 128 + ' and ConfigId = ' + 1 + ' and Date <= \'' + moment().format('YYYY-MM-DD HH:mm:ss') + "'", { type: models.sequelize.QueryTypes.SELECT });
            expect(mileSums[0].mileSum).not.to.be.equal(null);
            console.log('\t', mileSums[0].mileSum);
        });
    })

})

